/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.Circuit;
import br.ufg.inf.si.poo.formula1.Library.Library;
/**
 * Circuit
 * 
 * Versao 1.0
 * 
 * Data 20/01/2013
 * 
 * @author Igor
 */
public class Circuit {
    //Atributos
    private String raceDate;
    private String circuitName;
    private int firstGrandPrix;
    private int numberLaps;
    private double circuitLength;
    private double raceDistance;
    private long lapRecordTime;
    private String lapRecordDriver;
    private String country;
    private String city;
    
    //Construtores
    public Circuit(){
        this.raceDate = "";
        this.circuitName = "";
        this.firstGrandPrix = 0;
        this.numberLaps = 0;
        this.circuitLength = 0;
        this.raceDistance = 0;
        this.lapRecordTime = 0;
        this.lapRecordDriver = "";
        this.country = "";
        this.city = "";
    }
    
    public Circuit(
            String raceDate,
            String circuitName,
            int firstGrandPrix,
            int numberLaps,
            double circuitLength,
            double raceDistance,
            long lapRecordTime,
            String lapRecordDriver,
            String country,
            String city
            ){
        /* Esse construtor recebe estes parametros pois o sao os dados que 
         o arquivo INICIAl contem */
        this.raceDate = raceDate;
        this.circuitName = circuitName;
        this.firstGrandPrix = firstGrandPrix;
        this.numberLaps = numberLaps;
        this.circuitLength = circuitLength;
        this.raceDistance = raceDistance;
        this.lapRecordTime = lapRecordTime;
        this.lapRecordDriver = lapRecordDriver;
        this.country = country;
        this.city = city;
    }

    //Metodos Getters and Setters
    /**
     * Retorna o atributo raceDate (data da corrida)
     * @return atributo raceDate
     */
    public String getRaceDate() {  
        return raceDate;
    }

    /**
     * Altera o atributo raceDate (data da corrida)
     * @param atributo raceDate
     */
    public void setRaceDate(String raceDate) {  
        this.raceDate = raceDate;
    }

    /**
     * Retorna o atributo circuitName (nome do circuito)
     * @return atributo circuitName
     */
    public String getCircuitName() {
        return circuitName;
    }

    /**
     * Altera o atributo circuitName (nome do circuito)
     * @param atributo circuitName
     */
    public void setCircuitName(String circuitName) {
        this.circuitName = circuitName;
    }

    /**
     * Retorna o atributo firstGrandPrix (primeiro grande premio)
     * @return atributo firstGrandPrix
     */
    public int getFirstGrandPrix() {
        return firstGrandPrix;
    }

    /**
     * Altera o atributo firstGrandPrix (primeiro grande premio)
     * @param atributo firstGrandPrix
     */
    public void setFirstGrandPrix(int firstGrandPrix) {
        this.firstGrandPrix = firstGrandPrix;
    }

    /**
     * Retorna o atributo numberLaps (quantidade de voltadas da corrida)
     * @return atributo numberLaps
     */
    public int getNumberLaps() {
        return numberLaps;
    }

    /**
     * Altera o atributo numberLaps (quantidade de voltadas da corrida)
     * @param atributo numberLaps
     */
    public void setNumberLaps(int numberLaps) {
        this.numberLaps = numberLaps;
    }

    /**
     * Retorna o atributo circuitLength (tamanho do circuito)
     * @return atributo circuitLength
     */
    public double getCircuitLength() {
        return circuitLength;
    }

    /**
     * Altera o atributo circuitLength (tamanho do circuito)
     * @param atributo circuitLength
     */
    public void setCircuitLength(double circuitLength) {
        this.circuitLength = circuitLength;
    }

    /**
     * Retorna o atributo raceDistance (distance de uma volta)
     * @return atributo raceDistance
     */
    public double getRaceDistance() {
        return raceDistance;
    }

    /**
     * Altera o atributo raceDistance (distance de uma volta)
     * @param atributo raceDistance
     */
    public void setRaceDistance(double raceDistance) {
        this.raceDistance = raceDistance;
    }

    /**
     * Retorna o atributo lapRecordTime (tempo recorde de uma volta)
     * @return atributo lapRecordTime
     */
    public long getLapRecordTime() {
        return lapRecordTime;
    }

    /**
     * Altera  o atributo lapRecordTime (tempo recorde de uma volta) caso o record atual seja menor que o atingido
     * @param atributo lapRecordTime, caso o record atual seja menor que o atingido
     */
    public void setLapRecordTime(long lapRecordTime, String lapRecordDriver, int year) {
        if(lapRecordTime < this.lapRecordTime){
            this.lapRecordTime = lapRecordTime;
            this.lapRecordDriver = lapRecordDriver+ " (" + year + ")";
        }
    }

    /**
     * Retorna o atributo lapRecordDriver (piloto que superou o recorde de melhor volta)
     * @return atributo lapRecordDriver
     */
    public String getLapRecordDriver() {
        return lapRecordDriver;
    }

    /**
     * Retorna o atributo country (pais)
     * @return atributo country
     */
    public String getCountry() {
        return country;
    }

    /**
     * Altera o atributo country (pais)
     * @param atributo country
     */
    public void setCountry(String country) {
        this.country = country;
    }

    /**
     * Retorna o atributo city (cidade)
     * @return atributo city (cidade)
     */
    public String getCity() {
        return city;
    }

    /**
     * Altera o atributo city (cidade)
     * @param a cidade "city"
     */
    public void setCity(String city) {
        this.city = city;
    }

    //Outros Metodos
    /**
     * Reescrita do metodo toString
     * Retorna uma String com o relatório de dados da Circuitos
     * @return String com o relatório de dados da Circuitos
     */
    @Override
    public String toString(){
        String data = "";

        data += this.city + "\n"
                + "________________________________________________\n"
                + "Race Date:\t\t" + this.raceDate + "\n"
                + "Circuit Name:\t\t" + this.circuitName + "\n"
                + "First Grand Prix:\t" + this.firstGrandPrix + "\n"
                + "Number of Laps:\t\t" + this.numberLaps + "\n"
                + "Circuit Length:\t\t" + this.circuitLength + " km" + "\n"
                + "Race Distance:\t\t" + this.raceDistance +" km" + "\n"
                + "Lap Record:\t\t" + Library.convertMilliseconds(this.lapRecordTime,"MINUTOS") + "- " + this.lapRecordDriver + "\n";

        return data;
    }

    /**
     * Reescrita do metodo equals
     * Verifica se o piloto passado como paramentro e o mesmo piloto do objeto são iguais
     * @param anObject
     * @return 
     */
    @Override
    public boolean equals(Object anObject) {
        if(anObject instanceof Circuit){
            if(this.country.equals(((Circuit) anObject).getCountry())){
                return true;
            }
        }
        return false;
    }

    /**
     * Reescrita do hashCode, devido a reescrita do metodo equals
     * @return 
     */
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (this.country != null ? this.country.hashCode() : 0);
        return hash;
    }
}